package com.boguan.web.controller.device;

import com.boguan.common.core.controller.BaseController;
import com.boguan.common.core.domain.AjaxResult;
import com.boguan.common.core.domain.entity.SysUser;
import com.boguan.common.core.page.TableDataInfo;
import com.boguan.common.utils.SecurityUtils;
import com.boguan.common.utils.StringUtils;
import com.boguan.device.domain.Device;
import com.boguan.device.domain.DeviceAlarmLog;
import com.boguan.device.domain.DeviceLog;
import com.boguan.device.mapper.DeviceMapper;
import com.boguan.device.service.IDeviceAlarmService;
import com.boguan.device.service.IDeviceService;
import com.boguan.system.domain.SysNotice;
import com.boguan.system.service.ISysNoticeService;
import com.boguan.web.controller.device.message.domain.MessageDomain;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 设备报警信息
 */
@RestController
@RequestMapping("/device")
@Api(tags = "设备报警")
public class DeviceAlarmController extends BaseController {

    @Autowired
    private IDeviceAlarmService deviceAlarmService;

    @Autowired
    private DeviceMapper deviceMapper;


    @ApiOperation("报警管理")
    @GetMapping("deviceAlarmManage")
    public AjaxResult deviceAlarmManage(String deviceNo){
        startPage();
        return AjaxResult.success(getDataTable(deviceAlarmService.deviceAlarmManage(deviceNo)));
    }

    @ApiOperation("报警管理详情")
    @GetMapping("deviceAlarmManageDetail")
    public AjaxResult deviceAlarmManageDetail(String deviceId,String alarmTime){
        return AjaxResult.success(deviceAlarmService.deviceAlarmManageDetail(deviceId, alarmTime));
    }

    @ApiOperation("报警搜索")
    @GetMapping("deviceAlarmSearch")
    public AjaxResult deviceAlarmSearch( String device_num,String device_name, String status){
        return AjaxResult.success(deviceAlarmService.deviceAlarmSearch(device_num, device_name, status));
    }

    @ApiOperation("设备报警上下阈值")
    @PostMapping("deviceAlarmValue")
    public AjaxResult deviceAlarmValue(Long deviceId, String height,String low){
        Device device = deviceMapper.selectByPrimaryKey(deviceId);
        if(device!=null){
            device.setHeight(height);
            device.setLow(low);
            deviceMapper.updateByPrimaryKeySelective(device);
            return AjaxResult.success();
        }
         return AjaxResult.error();

    }
}
